﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DoveyGeneric
{
    /// <summary>
    /// 泛型方法（CommandMethod）、泛型类（）、泛型接口、泛型委托
    /// </summary>
    class Program
    {
        static void Main(string[] args)
        {
            int iValue = 3;
            string sValue = "sValue";
            DateTime dtValue = DateTime.Now;
            object oValue = new object();

            Console.WriteLine("**************GenericMethod*************");
            CommonMethod.Show<int>(iValue);
            CommonMethod.Show<string>(sValue);
            CommonMethod.Show<DateTime>(dtValue);
            CommonMethod.Show<object>(oValue);
            

            // 第一节0:48:00 2019-10-23

            // 泛型方法 一个方法满足多个类型的需求
            // 泛型类   一个类满足多个类型的需求
            // 泛型接口 一个接口满足多个类型的需求
            // 泛型委托 一个委托满足多个类型的需求


            // 泛型约束
            // 泛型约束的好处：
            // 获取更多的功能
            // 在调用时候，避免错误调用

            People people = new People()
            {
                Id = 111,
                Name = "Dovey"
            };

            Chinese chinese = new Chinese()
            {
                Id = 112,
                Name = "Shero"
            };

            Hubei hubei = new Hubei()
            {
                Id=113,
                Name="Darren"
            };

            Japanese japanese = new Japanese()
            {
                Id=114,
                Name="朝元爱"
            };
            Console.WriteLine("**************GenericConstraint*************");
            GenericConstraint.Show(people);
            GenericConstraint.Show(chinese);
            GenericConstraint.Show(hubei);
            //GenericConstraint.Show(japanese);
            Console.WriteLine();
            GenericConstraint.Work<Chinese>(chinese);
            GenericConstraint.Work<Hubei>(hubei);
            // GenericConstraint.Show2<Japanese>(japanese);  //错误，Japanese 没有继承IWork
            //GenericConstraint.Show2<People>(people); // 没有继承IWork


            Console.ReadKey();
        }
    }
}
